
import 'dart:convert';
import 'package:ichinesereader/models/book/BookLevel.dart';
import 'package:ichinesereader/models/common/Settings.dart';
import 'package:ichinesereader/models/student/StudentItem.dart';
import 'package:ichinesereader/models/teacher/TeacherDto.dart';

List<ClassDetails> classDetailsFromJson(String str) => List<ClassDetails>.from(
    json.decode(str).map((x) => ClassDetails.fromJson(x)));

String classDetailsToJson(List<ClassDetails> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class ClassDetails {
  ClassDetails({
    this.classId,
    this.className,
    this.createDate,
    this.classLevel,
    this.settings,
    this.viewReport,
    this.numBooks,
    this.numQuizzes,
    this.numOfAssignment,
    this.gameDisable,
    this.students,
    this.teachers,
    this.level,
  });

  String? classId;
  String? className;
  int? createDate;
  Level? classLevel;
  Settings? settings;
  bool? viewReport;
  int? numBooks;
  int? numQuizzes;
  int? numOfAssignment;
  bool? gameDisable;
  List<StudentItem>? students;
  List<TeacherDto>? teachers;
  String? level;

  factory ClassDetails.fromJson(Map<String, dynamic> json) => ClassDetails(
        classId: json["classId"],
        className: json["className"],
        createDate: json["createDate"],
        classLevel: json["classLevel"] != null
            ? Level.fromJson(json["classLevel"])
            : null,
        settings: json["settings"] != null
            ? Settings.fromJson(json["settings"])
            : null,
        viewReport: json["viewReport"],
        numBooks: json["numBooks"],
        numQuizzes: json["numQuizzes"],
        numOfAssignment: json["numOfAssignment"],
        gameDisable: json["gameDisable"],
        students: json["students"] != null
            ? List<StudentItem>.from(
                json["students"].map((x) => StudentItem.fromJson(x)))
            : null,
        teachers: json["teachers"] != null
            ? List<TeacherDto>.from(
                json["teachers"].map((x) => TeacherDto.fromJson(x)))
            : null,
        level: json["level"],
      );

  Map<String, dynamic> toJson() => {
        "classId": classId,
        "className": className,
        "createDate": createDate,
        "classLevel": classLevel != null ? classLevel?.toJson() : null,
        "settings": settings != null ? settings?.toJson() : null,
        "viewReport": viewReport,
        "numBooks": numBooks,
        "numQuizzes": numQuizzes,
        "numOfAssignment": numOfAssignment,
        "gameDisable": gameDisable,
        "students": students != null
            ? List<dynamic>.from(students!.map((x) => x.toJson()))
            : null,
        "teachers": teachers != null
            ? List<dynamic>.from(teachers!.map((x) => x.toJson()))
            : null,
        "level": level,
      };
}
